package com.example.ceshi;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

import com.example.ceshi.Bean.BrandBean;
import com.example.ceshi.Bean.BrandDetail;
import com.example.ceshi.utils.NetUtil;

import java.util.Objects;

public class BrandActivity extends AppCompatActivity {
    private String strData="";
    private BrandDetail brandDetail;
    private String TAG2="ming";
    private String number="";
    private Handler mHandler= new Handler(Looper.myLooper()) {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);

            if (msg.what == 0) {
                strData = (String) msg.obj;

//                    Log.d(TAG2,"得到的数据:"+strData);
//                parseJsonData(strData);
                if (Objects.equals(brandDetail.getCode(), "200")) {
                    //查到详细星系
                    Toast.makeText(BrandActivity.this, "成功查询到信息", Toast.LENGTH_LONG).show();
                } else {
                    //未查到详细信息
                    Toast.makeText(BrandActivity.this, "未查询到信息", Toast.LENGTH_LONG).show();
                }
                Log.d(TAG2, "封装的brandbean:" + brandDetail.toString());

            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_brand);

//        假数据 真实数据需要动态捕获
        number="78293084788343";
//        getBrand(number);
        Bundle bundle = getIntent().getExtras();
        Log.d(TAG2,bundle.getString("number"));
    }

    public void getBrand(String number) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String stringFromNet = NetUtil.getBrand(number);

                Message message = new Message();
                message.what = 0;
                message.obj = stringFromNet;

                mHandler.sendMessage(message);
            }
        }).start();
//        Toast.makeText(this, "任务完成", Toast.LENGTH_LONG).show();
    }
}